package com.dronff.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dronff.common.ResponseResult;
import com.dronff.common.feign.UserFeign;
import com.dronff.mapper.UserMapper;
import com.dronff.pojo.User;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author tyf
 * @date 2022/7/21 17:25
 */
@RestController
public class UserController implements UserFeign {
    @Resource
    UserMapper userMapper;
    @Override
    public ResponseResult login(Integer id, String password) {
        if(userMapper.selectOne(new QueryWrapper<User>().eq("id",id).eq("password",password))!=null){
            return new ResponseResult(200,"登录成功");
        }
        return new ResponseResult(500,"登录失败");
    }
    @GlobalTransactional
    @Override
    public ResponseResult dec(Integer id, Integer pri) {
        if(userMapper.decUserCoin(id,pri)==1){
            return new ResponseResult(200,"扣除成功");
        }
        return new ResponseResult(500,"扣除失败");
    }
}
